<?php

use yii\db\Schema;
use yii\db\Migration;

class m160322_072431_add_user_account_privileges_fields extends Migration
{
    public function up()
    {
        $this->addColumn('{{%user}}', 'adnetwork_slot', 'varchar(128) not null default 1 comment "0 for all adnetwork, 1 for vamaker, \',\' as seperator" after user_type');
        $this->addColumn('{{%user}}', 'traffic_slot', 'varchar(128) not null default "1,2,3,4" comment "0 for traffic, 1 for pc display, 2 for pc video, 3 for mobile banner, 4 for mobile video, \',\' as seperator" after adnetwork_slot');
        $this->addColumn('{{%user}}', 'media_slot', 'varchar(128) not null default 0 comment "0 for all media, \',\' as seperator, adnetwork_media table id" after traffic_slot');
        $sql = <<<FINE
create table if not exists {{%adnetwork_media}} (
    id int(10) not null auto_increment,
    ad_network_id int(10) not null default 1 comment '1 for vamaker, adnetwork table id',
    media_id varchar(64) not null comment 'media id on ssp platform',
    media_name varchar(64) not null comment 'media name on ssp platform',
    last_update timestamp not null default current_timestamp on update current_timestamp,
    primary key (id)
)engine=innodb default charset=utf8;
FINE;
        $this->execute($sql);
    }

    public function down()
    {
        $this->dropTable('{{%adnetwork_media}}');
        $this->dropColumn('{{%user}}', 'adnetwork_slot');
        $this->dropColumn('{{%user}}', 'traffic_slot');
        return $this->dropColumn('{{%user}}', 'media_slot');
    }

    /*
    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
    }

    public function safeDown()
    {
    }
    */
}
